import csv
from docx import Document

path = r'E:\BaiduNetdiskWorkspace\1701864\123同步文件夹\确有专长笔记\中医内科学\实践技能歌诀.docx'

# 去掉序号后的疾病列表
diseases = [
    "感冒", "咳嗽", "哮病", "喘证", "肺痨", "肺胀", "心悸", "胸痹", "不寐", "痫病",
    "胃痛", "呕吐", "腹痛", "泄泻", "痢疾", "便秘", "胁痛", "黄疸", "头痛", "眩晕",
    "中风", "痴呆", "水肿", "淋证", "郁证", "血证", "消渴", "内伤发热", "痹证",
    "痿证", "腰痛", "乳癖", "湿疮", "痔", "肠痈", "崩漏", "痛经",
    "绝经前后诸证", "带下病", "胎漏、胎动不安", "不孕症", "肺炎喘嗽", "小儿泄泻",
    "积滞", "鹅口疮", "水痘", "手足口病", "麻疹"
]

# 打开现有文档
doc = Document(path)

# 遍历所有段落
num = 0
cardData = []
is_first_line = True
is_get_bm = False
bm = None
gj = None
for para in doc.paragraphs:
    # cardInfo =
    zx_str_list = []
    print(para.text, para.style.name)
    if para.style.name == "Normal":

        num += 1
        # print(num)
        bm = para.text.split('）')[-1]  # 病名

    if para.style.name == "No Spacing" and bm and gj is None:
        gj = para.text

    if para.style.name == "No Spacing" and bm and gj:
        zx_str_list.append(para.text)

    zx_str = '\n'.join(zx_str_list)
    print(bm)
    cardData.append({"bm": bm.strip(),
                       "gj": gj.strip(),
                       "zx": zx_str.strip()})
    bm = None
    gj = None
    zx_str_list = []

print(cardData)